using ASP;
using HoWave.Common;
using HoWave.Web.Admin;
using System;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_ManageTemplate : Admin, IRequiresSessionState
{
	protected string m_Dir = "";
	protected string m_TemplateDir = "";
	private FileIO m_fileio = null;
	protected Literal CurrentDir;
	protected HyperLink GoPrePage;
	protected GridView GridView1;
	protected Button CreateTemplateButton;
	protected Button UploadTem;
	protected Button DeleteButton;
	protected Button CreateTem;
	protected TextBox AddFolder;
	protected RequiredFieldValidator rfv1;
	protected Button AddFolder_Button;
	protected FileUpload UploadTemplate;
	protected Button UploadTemButton;
	protected Label CanUpLoadType;
	protected Label CanNotUpLoadTypeMsg;
	protected TextBox ReNameText;
	protected Button ReNameButton;
	protected ObjectDataSource ObjectDataSource1;
	protected FileIO m_FileIO
	{
		get
		{
			FileIO result;
			if (this.m_fileio == null)
			{
				result = new FileIO();
			}
			else
			{
				result = this.m_fileio;
			}
			return result;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(44))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Template");
			base.WriteRightErrMsg();
		}
		this.m_TemplateDir = this.config["TemplateDir"].ToString().Replace("/", "\\");
		this.BindPage();
	}
	protected void BindPage()
	{
		if (base.Request["Dir"] != null && base.Request["Dir"] != "")
		{
			this.m_Dir = base.Request["Dir"];
		}
		if (this.m_Dir != null && this.m_Dir != "")
		{
			this.CurrentDir.Text = this.m_Dir;
			this.m_Dir.Replace("\\", "/");
			int length = this.m_Dir.LastIndexOf("/");
			string s = this.m_Dir.Substring(0, length);
			this.GoPrePage.NavigateUrl = "?Dir=" + base.Server.UrlEncode(s);
			this.m_Dir = this.m_Dir.Replace("/", "\\");
		}
		else
		{
			this.CurrentDir.Text = "/";
			this.m_Dir = "\\";
		}
		if (this.m_Dir.LastIndexOf("\\") != this.m_Dir.Length - 1)
		{
			this.m_Dir += "\\";
		}
		this.GridView1.DataSource = this.m_FileIO.GetDirectoryInfo(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir));
		this.GridView1.DataBind();
		if (!base.admin.CheckAdminPower(45))
		{
			this.CreateTemplateButton.Enabled = false;
			this.AddFolder.Enabled = false;
			this.CreateTem.Enabled = false;
			this.UploadTem.Enabled = false;
			this.ReNameButton.Enabled = false;
			this.AddFolder_Button.Enabled = false;
			this.UploadTemButton.Enabled = false;
		}
		if (!base.admin.CheckAdminPower(46))
		{
			this.DeleteButton.Enabled = false;
		}
	}
	protected void DeleteButton_Click(object sender, EventArgs e)
	{
		string text = base.Request["chkSelect"];
		if (!string.IsNullOrEmpty(text))
		{
			this.DeleteTem(text);
		}
		this.GridView1.DataSource = this.m_FileIO.GetDirectoryInfo(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir));
		this.GridView1.DataBind();
	}
	protected void DeleteButton_Click(object sender, CommandEventArgs e)
	{
		if (e.CommandArgument != null)
		{
			string text = e.CommandArgument.ToString();
			if (!string.IsNullOrEmpty(text))
			{
				this.DeleteTem(text);
			}
			this.GridView1.DataSource = this.m_FileIO.GetDirectoryInfo(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir));
			this.GridView1.DataBind();
		}
	}
	protected void DeleteTem(string m_IDArray)
	{
		if (m_IDArray.Contains(","))
		{
			string[] array = m_IDArray.Split(new char[]
			{
				','
			});
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				string s = array2[i];
				this.m_FileIO.DeleteFileFolder(Fetch.GetTruePath(base.Server.UrlDecode(s)));
			}
		}
		else
		{
			this.m_FileIO.DeleteFileFolder(Fetch.GetTruePath(base.Server.UrlDecode(m_IDArray)));
		}
	}
	public string HasFile(string m_IDArray)
	{
		int num = 0;
		string[] array = m_IDArray.Split(new char[]
		{
			'/'
		});
		string result;
		if (m_IDArray.IndexOf(".") > 0)
		{
			result = "return DeleteFile('2')";
		}
		else
		{
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				string s = array2[i];
				bool flag = this.IsExitFile(Fetch.GetTruePath(base.Server.UrlDecode(s)));
				if (flag)
				{
					num = 1;
					break;
				}
			}
			result = "return DeleteFile('" + num + "')";
		}
		return result;
	}
	private bool IsExitFile(string filePath)
	{
		bool result;
		if (Directory.Exists(filePath) && Directory.GetFiles(filePath).Length > 0)
		{
			result = true;
		}
		else
		{
			string[] directories = Directory.GetDirectories(filePath);
			for (int i = 0; i < directories.Length; i++)
			{
				string filePath2 = directories[i];
				this.IsExitFile(filePath2);
			}
			result = false;
		}
		return result;
	}
	protected void AddNewTemplateButton_Click(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(45))
		{
			base.WriteLog("AddNew", Language.GetAdminMsg("Log/Access", "0"), "Template");
			base.WriteRightErrMsg();
		}
		base.Response.Redirect("Admin_Template.aspx?action=add&Dir=" + this.m_Dir);
	}
	protected void AddNewFolder_Click(object sender, EventArgs e)
	{
		string text = this.AddFolder.Text;
		this.m_FileIO.CreateFolder(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir + "\\" + text));
		this.GridView1.DataSource = this.m_FileIO.GetDirectoryInfo(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir));
		this.GridView1.DataBind();
	}
	protected void Copy_OnCommand(object sender, CommandEventArgs e)
	{
		string text = e.CommandName.ToString();
		string truePath = Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir);
		this.m_FileIO.CopyDirectoryFile(truePath + text, truePath + "复件 " + text);
		this.GridView1.DataSource = this.m_FileIO.GetDirectoryInfo(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir));
		this.GridView1.DataBind();
	}
	protected void ReNameButton_Click(object sender, EventArgs e)
	{
		string text = base.Request["old_name"];
		string text2 = this.ReNameText.Text;
		string truePath = Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir);
		if (text2 != "" && text != "" && text2 != text)
		{
			this.m_FileIO.ReName(truePath + text2, truePath + text);
		}
		this.GridView1.DataSource = this.m_FileIO.GetDirectoryInfo(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir));
		this.GridView1.DataBind();
	}
	protected void UploadTemplate_Click(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(45))
		{
			base.WriteLog("AddNew", Language.GetAdminMsg("Log/Access", "0"), "Template");
			base.WriteRightErrMsg();
		}
		string text = this.CanUpLoadType.Text.ToLower();
		string fileName = this.UploadTemplate.PostedFile.FileName;
		string text2 = fileName;
		string text3 = text2.Substring(text2.LastIndexOf(".")).ToString().Replace(".", "");
		if (text.IndexOf(text3.ToLower()) < 0)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Template/UpLoadFileErr", this.CanNotUpLoadTypeMsg.Text.ToString()), "");
		}
		string truePath = Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir + text2);
		try
		{
			this.m_FileIO.UploadFile(this.UploadTemplate.PostedFile, truePath);
		}
		catch (Exception ex)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Template/UpLoadFileErr", ex.Message.ToString()), "");
		}
		this.GridView1.DataSource = this.m_FileIO.GetDirectoryInfo(Fetch.GetTruePath(this.m_TemplateDir + this.m_Dir));
		this.GridView1.DataBind();
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			if (gridViewRow.RowType == DataControlRowType.DataRow)
			{
				gridViewRow.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
				gridViewRow.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
				HyperLink hyperLink = (HyperLink)gridViewRow.Cells[1].FindControl("name_url");
				string navigateUrl = hyperLink.NavigateUrl;
				if (gridViewRow.Cells[3].Text == "文件夹")
				{
					hyperLink.NavigateUrl = "?Dir=" + base.Server.UrlEncode("/" + navigateUrl.Replace(this.m_TemplateDir.Replace("\\", "/"), ""));
				}
				else
				{
					hyperLink.NavigateUrl = "Admin_Template.aspx?action=modify&Dir=" + base.Server.UrlEncode("/" + navigateUrl.Replace(this.m_TemplateDir.Replace("\\", "/"), ""));
				}
			}
		}
	}
}
